<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" id="btn1" value="点赞(0)">
    <!-- <input type="button" id="btn2" value="点赞(0)">
    <input type="button" id="btn3" value="点赞(0)">
    <input type="button" id="btn4" value="点赞(0)"> -->
    <button>点赞(0)</button>
    <button>点赞(0)</button>
    <button>点赞(0)</button>
    <button>点赞(0)</button>
    <script type="text/javascript">
        var btn1 = document.getElementById('btn1');
        // var btn2 = document.getElementById('btn2');
        // var btn3 = document.getElementById('btn3');
        // var btn4 = document.getElementById('btn4');

        function checknum() {
            var val = 1;
            return function() {
                this.innerHTML = "点赞(" + (val++) + ")";
                // console.log(val);
            }
        }
        btn1.onclick = checknum();
        //获取所有的按钮
        var btnObjs = document.getElementsByTagName("button");
        //循环遍历每个按钮,注册点击事件
        for (var i = 0; i < btnObjs.length; i++) {
            //注册事件
            btnObjs[i].onclick = checknum();
        }
    </script>
</body>

</html>